<html>
<head><meta charset="utf-8"><title>Sized vs thin · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html">Sized vs thin</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="188964684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/188964684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#188964684">(Feb 24 2020 at 20:52)</a>:</h4>
<p>Does <code>T: Sized</code> necessarily imply that <code>*const T</code> is a thin pointer? This is the case in today’s Rust, but do we want to "promise" or document that it will always be?</p>



<a name="188967185"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/188967185" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#188967185">(Feb 24 2020 at 21:20)</a>:</h4>
<p><code>std::mem::transmute::&lt;*const T, usize&gt;</code> is allowed, so it looks like it's guaranteed (at least on current targets).</p>



<a name="188973748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/188973748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#188973748">(Feb 24 2020 at 22:36)</a>:</h4>
<p>I believe this is something we could not change, yes</p>



<a name="188996573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/188996573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#188996573">(Feb 25 2020 at 07:17)</a>:</h4>
<p>Good point, that transmute is allowed even in generic contexts for a type parameter without <code>?Sized</code></p>



<a name="189019561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/189019561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#189019561">(Feb 25 2020 at 13:36)</a>:</h4>
<p>It’ll just operate on the data pointer I believe?</p>



<a name="189019611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/189019611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#189019611">(Feb 25 2020 at 13:37)</a>:</h4>
<p><span class="user-mention" data-user-id="119009">@eddyb</span> argued in the past that the vtable pointer is actually the part of <code>T</code> not <code>*const</code>.</p>



<a name="189019635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/189019635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#189019635">(Feb 25 2020 at 13:37)</a>:</h4>
<p>something along those lines.</p>



<a name="189019697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/189019697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#189019697">(Feb 25 2020 at 13:38)</a>:</h4>
<p>And so it is your responsibility to reconstruct the right vtable pointer if you want to convert <code>usize</code> to a fat pointer.</p>



<a name="189042461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/Sized%20vs%20thin/near/189042461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Simon Sapin <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/Sized.20vs.20thin.html#189042461">(Feb 25 2020 at 17:47)</a>:</h4>
<p>Yes you can cast a fat pointer with <code>as</code> and get the data part only, but <code>transmute</code> checks that <code>size_of::&lt;*const T&gt;() == size_of::&lt;usize&gt;()</code></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>